<?php
namespace Jykj\Quicklogin\Domain\Repository;

/***************************************************************
 *
 *  Copyright notice
 *
 *  (c) 2015 WHB <wanghongbin@ngoos.org>
 *
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
 *  free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  The GNU General Public License can be found at
 *  http://www.gnu.org/copyleft/gpl.html.
 *
 *  This script is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  This copyright notice MUST APPEAR in all copies of the script!
 ***************************************************************/

/**
 * The repository for FrontendUser
 */
class FrontendUserRepository extends \TYPO3\CMS\Extbase\Persistence\Repository 
{
    public function initializeObject()
    {
        $querySettings = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QuerySettingsInterface');
        $querySettings->setRespectStoragePage(FALSE);
        $this->setDefaultQuerySettings($querySettings);
    }

	/**
	 * 查看用户是否绑定
	 */
	public function findByOpenid($openid,$filed){
		
		$query = $this->createQuery();

		$query->matching($query->equals(
			$filed,$openid
		));
		$result = $query->execute();
		
		if($result->count() > 0){
			return $result->getFirst();
		}
		return false;
	}
	
	
	/**
	 * 检查相应的字段是否已存在
	 */
	public function checkFiledIfExist($filed_name = 'username', $filed_value){
		
		$query = $this->createQuery();
		$query->matching($query->equals(
			$filed_name,$filed_value
		));
		$result = $query->execute();
		
		if($result->count() > 0){
			return true;
		}
		return false;
	}
	
	public function getGroup($uids){
		$list = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'fe_groups', 'deleted=0 and hidden=0 and uid in ('.$uids.')', '', 'uid desc'); ;
		return $list;
	}
}